package com.vmj.instructions.reserved;

import com.vmj.heap.VMClass;
import com.vmj.heap.Method;
import com.vmj.instructions.base.NoOperandsInstruction;
import com.vmj.natives.NativeMethod;
import com.vmj.natives.Registry;
import com.vmj.rtda.Frame;

/**
 * Created by yangshoujun on 2017/9/16 上午12:58.
 */
public class InvokeNative extends NoOperandsInstruction{
    @Override
    public void execute(Frame frame) {
        Method method = frame.getMethod();
        VMClass clazz = method.getClazz();
        String className = clazz.getName();
        String methodName = method.getName();
        String descripor = method.getDescriptor();
        NativeMethod nativeMethod = Registry.findNativeMethod(className, methodName, descripor);

        String methodInfo = className + "~" + methodName + "~" + descripor;
        if(nativeMethod == null) {
            throw new RuntimeException("java.lang.UnsatisfiedLinkError: " + methodInfo);
        }
        nativeMethod.execute(frame);
    }
}
